package LinkList;

import java.util.*;

public class Test {
        public static void main(String[] args) {
                LinkedList<Integer> linkedList2 = new LinkedList<Integer>();
                linkedList2.add(1);//默认都是尾插
                linkedList2.addLast(3);
                linkedList2.addLast(4);
                linkedList2.addLast(5);
                System.out.println(linkedList2);

                System.out.println("===== ListIterator ====");
                ListIterator<Integer> lit2 = linkedList2.listIterator(linkedList2.size());
                while (lit2.hasPrevious()) {
                        System.out.print(lit2.previous() + " ");
                }
                System.out.println();

                System.out.println("===== ListIterator ====");
                ListIterator<Integer> lit = linkedList2.listIterator();
                while (lit.hasNext()) {
                        System.out.print(lit.next() + " ");
                }
                System.out.println();

                System.out.println("===== Iterator ====");
                Iterator<Integer> it = linkedList2.iterator();
                while (it.hasNext()) {
                        System.out.print(it.next() + " ");
                }
                System.out.println();


                System.out.println("=====for each====");

                for (Integer x : linkedList2) {
                        System.out.print(x + " ");
                }
                System.out.println();

                System.out.println("=====for====");
                for (int i = 0; i < linkedList2.size(); i++) {
                        System.out.print(linkedList2.get(i) + " ");
                }
                System.out.println();


        }

        public static void main6(String[] args) {
                List<Integer> linkedList1 = new LinkedList<>();
                LinkedList<Integer> linkedList2 = new LinkedList<>();
                linkedList2.add(1);//默认都是尾插
                linkedList2.addFirst(2);
                linkedList2.addLast(3);
                linkedList2.addLast(4);
                linkedList2.addLast(5);
                System.out.println(linkedList2);

                ArrayList<Integer> list = new ArrayList<>();
                list.add(11);
                list.add(21);
                list.add(31);

                linkedList2.addAll(list);

                System.out.println(linkedList2);

                linkedList2.remove(2);
                System.out.println(linkedList2);

        }
        public static void main7(String[] args) {
        MyLinkList myLinkList = new MyLinkList();
        myLinkList.addLast(1);
        myLinkList.addLast(2);
        myLinkList.addLast(3);
        myLinkList.addLast(4);
        myLinkList.addLast(5);
        myLinkList.addLast(1);
        myLinkList.addLast(1);
        myLinkList.addLast(1);
        myLinkList.addLast(1);

        myLinkList.display();


        myLinkList.addIndex(3, 9);
        myLinkList.clear();
        myLinkList.addIndex(3,9);
        myLinkList.display();

    }
}
